package zucc.edu.cn.chengchengparttime.My;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

import zucc.edu.cn.chengchengparttime.LoginAndReg.LoginActivity;
import zucc.edu.cn.chengchengparttime.MainActivity;
import zucc.edu.cn.chengchengparttime.R;

public class MyFragment extends Fragment {
    private Context context;
    private List<String> data=new ArrayList<>(); //数据列表

    private TextView personal_data_text;
    private ImageView personal_data_next;
    private TextView mywork_text;
    private ImageView mywork_next;
    private TextView appsetting_text;
    private ImageView appsetting_next;
    private TextView aboutapp_text;
    private ImageView aboutapp_next;
    private TextView ID;

    public MyFragment(){}

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_my,container,false);
        context = this.getActivity();

        //定义跳转图标
        personal_data_next=view.findViewById(R.id.personal_data_next);
        mywork_next=view.findViewById(R.id.mywork_next);
        appsetting_next=view.findViewById(R.id.appsetting_next);
        aboutapp_next=view.findViewById(R.id.aboutapp_next);
        //定义跳转的文本
        personal_data_text=view.findViewById(R.id.personal_data_text);
        mywork_text=view.findViewById(R.id.mywork_text);
        appsetting_text=view.findViewById(R.id.appsetting_text);
        aboutapp_text=view.findViewById(R.id.aboutapp_text);
        ID=view.findViewById(R.id.ID);

        ID.setText(LoginActivity.getCurrentUser());
        //跳转图标点击事件响应
        personal_data_next.setOnClickListener(view1 -> { //个人资料
            Toast.makeText(context, "点击了个人资料" , Toast.LENGTH_SHORT).show();
            //跳转到个人资料界面
            Intent intent = new Intent(context, MyPersonalData.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });
        mywork_next.setOnClickListener(view1 -> { //我的报名
            Toast.makeText(context, "点击了我的报名" , Toast.LENGTH_SHORT).show();
            //跳转到我的报名界面
            Intent i=new Intent();
            i.setClass(this.context, MainActivity.class);
            //一定要指定是第几个pager，这里填写2
            i.putExtra("id",2);
            startActivity(i);
        });
        appsetting_next.setOnClickListener(view1 -> { //APP设置
            Toast.makeText(context, "点击了APP设置" , Toast.LENGTH_SHORT).show();
            //跳转到APP设置界面
            Intent intent = new Intent(context, MyAppSetting.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });
        aboutapp_next.setOnClickListener(view1 -> { //关于APP
            Toast.makeText(context, "点击了关于APP" , Toast.LENGTH_SHORT).show();
            //跳转到关于APP界面
            Intent intent = new Intent(context, MyAboutApp.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });

        //跳转文本点击事件响应
        personal_data_text.setOnClickListener(view1 -> { //个人资料
            Toast.makeText(context, "点击了个人资料" , Toast.LENGTH_SHORT).show();
            //跳转到个人资料界面
            Intent intent = new Intent(context, MyPersonalData.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });
        mywork_text.setOnClickListener(view1 -> { //我的报名
            Toast.makeText(context, "点击了我的报名" , Toast.LENGTH_SHORT).show();
            //跳转到我的报名界面
            Intent i=new Intent();
            i.setClass(this.context, MainActivity.class);
            //一定要指定是第几个pager，这里填写2
            i.putExtra("id",2);
            startActivity(i);
        });
        appsetting_text.setOnClickListener(view1 -> { //APP设置
            Toast.makeText(context, "点击了APP设置" , Toast.LENGTH_SHORT).show();
            //跳转到APP设置界面
            Intent intent = new Intent(context, MyAppSetting.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });
        aboutapp_text.setOnClickListener(view1 -> { //关于APP
            Toast.makeText(context, "点击了关于APP" , Toast.LENGTH_SHORT).show();
            //跳转到关于APP界面
            Intent intent = new Intent(context, MyAboutApp.class);
            Log.d("context",context.getPackageName());
            startActivity(intent);
        });

        return view;
    }
}
